package com.ama.utils;

import com.ama.utils.urltoImage.ImplementsCmd;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

public class UrlToImageUtils {

    public static void main(String[] args) {
        urlToImage("http://localhost:8080/staff_page/s_cost.jsp?costId=1342087798903029762","CostPNG");
    }

    public static void urlToImage(String url , String filename){
        String picname = filename+".png" ;
        String jsname = filename+".js";
        ImplementsCmd.reload( url, picname,jsname);

        String cmd1 = "cmd /c cd" + " src/main/java/com/ama/utils/urltoImage/phantomjs/" ;
        String cmd  = cmd1 + "&&phantomjs.exe " + jsname;
        ImplementsCmd.implcmd(cmd);

        String fromPath = "src/main/java/com/ama/utils/urltoImage/phantomjs/"+picname;
        String toPath = "D:\\";
        File fromFile = new File(fromPath);
        File toFile = new File(toPath,picname);

        System.out.println(fromPath);
        System.out.println(toPath);

        try {
            new Thread().sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        try {
            FileUtils.copyFile(fromFile,toFile );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
